﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Facebook;

namespace WebApp.Controllers
{
    public class AccountController : ApplicationController
    {
        public const String LOGOUT_URL = "https://www.facebook.com/logout.php?next={0}&access_token={1}";

        public ActionResult Login()
        {
            HttpContextBase context = this.HttpContext;
            String authToken = context.Request["authToken"];
            context.Session["authToken"] = authToken;
            context.Response.Redirect(Url.Action("Index", "Profile"));
            return null;
        }

        public ActionResult Logout()
        {
            HttpContextBase context = this.HttpContext;
            this.HttpContext.Session.Abandon();
            context.Response.Redirect(Url.Action("Index", "Profile"));
            return null;
        }

        public ActionResult Index()
        {
            try
            {
                if (HttpContext.Session["authToken"] != null)
                {
                    HttpContext.Response.Redirect(Url.Action("Index", "Profile"));
                    return null;
                }
            }
            catch (Exception e)
            {
            }
            return View("Login");
        }
    }
}
